<?php
/*
+--------------------------------------------------------------------------
|   phpBIZ v3.0  full version
|   ========================================
|   by taft@wjl.cn yejun@wjl.cn pianyao@wjl.cn
|   http://www.phpbiz.cn http://www.wjl.cn
|   all rights reserved
+---------------------------------------------------------------------------
|
|   > 最后修改日期：2005-4-30 2006-2-8
|
+--------------------------------------------------------------------------
*/
!class_exists('Debug') && exit('Forbidden');
$idx = new Adver;
class Adver
{
	function Adver()
	{
		global $BIZ,$INCOME,$CONF,$_LEVEL;
		
		$this -> upload_dir = stripslashes($CONF['upload_dir']);
		$this -> seller_data = new manager($BIZ->seller['seller_id']);

		//---------------------------------------
		// Kill globals - globals bad, Homer good.
		//---------------------------------------
		
		$tmp_in = array_merge( $_GET, $_POST, $_COOKIE );
		
		foreach ( $tmp_in as $k => $v )	unset($$k);
		
		if ( empty($BIZ->seller['seller_id']) or $BIZ->seller['seller_id']=="" or $BIZ->seller['seller_id']==0 )
		{
			$BIZ->error( "用户没有登陆，不能使用此功能","?act=Login&code=00" );
		}
		if( !$this -> seller_data->check($INCOME[act]) )
            $BIZ -> error("该等级用户不享有该功能。");

	    //--------------------------------------------
        // Check viewing permissions, etc
	    //--------------------------------------------
						
		if ( empty($BIZ->seller['seller_id']) or $BIZ->seller['seller_id']=="" or $BIZ->seller['seller_id']==0 )
		{
			$BIZ->error( "用户没有登陆，不能使用此功能","?act=Login&code=00" );
		}
	    if( $BIZ->seller['seller_check_status']=='uncheck' )
		{
			$this -> seller_data->control_panel("nocharge");
		}elseif( ($data=$this -> seller_data->get_seller_data("end_time,property_id"))&& $data['end_time']<time()&&$_LEVEL[$data['property_id']][1]>0 )
		{
			$this -> seller_data->control_panel("due");
		}else
		{
			$BIZ -> assign('code',$INCOME['code']);
			$BIZ-> nav_link[] =array ("商家控制台","index.php?act=Promote");
			switch($INCOME['code'])
			{
				case '00':     // display general seller info
				   $this -> seller_data->control_panel();
				   break;
				case '28':
					$BIZ-> nav_link[] = array("发布新广告","");
				    break;
				case '29':
					$this -> do_add_adver();
				   break;
				case '30':                         //管理我的广告
					$BIZ-> nav_link[] = array("管理已发布广告","");
				  $this -> adv_list();
					break;
				case '31':
					$BIZ -> nav_link[] = array("广告管理","");
				 $this -> modify_adv();   //修改广告表单
					break;
				case '32':
					$this -> do_modify_adv();
				   break;
				case '33':
					$this -> active_adv();   //提前广告
				   break;
				case '34':
					$this -> del_adv();      //删除广告
				  break;
				default:
				  $this -> seller_data->control_panel();
			}
		}
		$BIZ -> output('Adver.tpl');
	}
	function do_add_adver()
	{//29
		global $INCOME,$DB,$BIZ,$feedb;

		if( $this -> seller_data ->consume($feedb['issue_adv']) ===false ) $BIZ -> error("提示：您的可用消费金额已不足！");
		$this -> seller_data -> consume_log($feedb['issue_adv'],"发布一条广告信息",$BIZ ->seller[seller_id]);
		$lad=$INCOME['ad'];
		$lad['info_active_time'] = time();
		$lad['info_writer']=$BIZ -> seller['seller_logaccount'];
		$lad['info_owner_id']=$BIZ -> seller['seller_id'];
		$lad['info_type'] = INFO_ADV;

		$DB->db_form_insert("biz_info",$lad);
	    
        $BIZ ->redirect_screen("恭喜！您已经成功发布了一条广告。消费".$feedb['issue_adv'],"?act=Adver&code=30");	

	}
	function adv_list()
	{
		global $INCOME,$DB,$BIZ;

		$DB -> db_query("SELECT * FROM biz_info WHERE info_owner_id=".$BIZ->seller['seller_id']." AND info_type=".INFO_ADV." ORDER BY info_active_time DESC");
        while($r=$DB -> db_fetch_row() )
		{
			$tm = date("Y-m-d H:i",$r['info_active_time']);
			$adl[] = array($r[info_title],$tm,$r[id]);
		}
        $BIZ -> assign("adl",$adl);
		return;
	}
	function modify_adv()
	{
		global $INCOME,$DB,$BIZ;

		$id = intval($INCOME['AID']);
		$DB -> db_query("SELECT * FROM biz_info WHERE id=".$id." LIMIT 1");
		$ad = $DB -> db_fetch_row();
		$BIZ ->assign("ad",$ad);
		return;
	}
	function do_modify_adv()
	{
		global $INCOME,$DB,$BIZ;

		$aid = intval($INCOME['AID']);
		$ad= $INCOME['ad'];

		$DB -> db_form_update("biz_info",$ad,"id=".$aid);
        $BIZ ->redirect_screen("恭喜！您已经成功更新了广告","?act=Adver&code=30");	
	}
	function active_adv()
	{//33
		global $DB,$BIZ,$INCOME,$feedb;

		if( $this -> seller_data ->consume($feedb['up_adv']) ===false ) $BIZ -> error("提示：您的可用消费金额已不足！");
		$this -> seller_data -> consume_log($feedb['up_adv'],"提前广告排序",$BIZ ->seller[seller_id]);
		$aid = intval($INCOME['AID']);
		$ad['info_active_time'] = time();
		$DB -> db_form_update("biz_info",$ad,"id=".$aid);
       
        $BIZ ->redirect_screen("恭喜！您已经成功提前了广告。消费".$feedb['up_adv'],"?act=Adver&code=30");	
	}
	function del_adv()
	{//34
		global $DB,$BIZ,$INCOME;
		$aid = intval($INCOME['AID']);
		$DB -> db_query("DELETE FROM biz_info WHERE id=".$aid);
        $BIZ ->redirect_screen("恭喜！您已经成功删除了一条广告","?act=Adver&code=30");	
	}

}
?>